package com.cch.cooperation.api.zone.controller;

import com.cch.cooperation.api.auth.dto.LoginUserDTO;
import com.cch.cooperation.api.zone.dto.ZoneUserApplyAuditDTO;
import com.cch.cooperation.api.zone.dto.ZoneUserApplyDTO;
import com.cch.cooperation.api.zone.dto.ZoneUserApplyJoinDTO;
import com.cch.cooperation.api.zone.dto.ZoneUserDelDTO;
import com.cch.cooperation.api.zone.service.ZoneUserApplyServiceImpl;
import com.cch.cooperation.api.zone.service.ZoneUserServiceImpl;
import com.cch.cooperation.common.web.response.Response;
import com.cch.cooperation.common.web.session.Session;
import com.cch.cooperation.common.web.session.SessionManager;
import com.cch.cooperation.dao.zone.dto.ZoneUserDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 空间用户加入申请接口
 *
 * @author cch
 */
@Api(tags = "空间用户加入申请接口")
@RestController
@RequestMapping("/api/zone/user/apply")
public class ZoneUserApplyController {

    @Resource
    private ZoneUserApplyServiceImpl zoneUserApplyService;
    @Resource
    private SessionManager sessionManager;

    @ApiOperation("查询申请列表")
    @GetMapping("/queryList")
    public Response<List<ZoneUserApplyDTO>> queryList(@ApiParam(value = "空间id", required = true) @RequestParam("zoneId") String zoneId) {
        Session<LoginUserDTO> session = sessionManager.get();
        List<ZoneUserApplyDTO> data = zoneUserApplyService.queryUserList(session.getData().getId(), zoneId);
        return Response.success(data);
    }

    @ApiOperation("申请加入空间")
    @PostMapping("/join")
    public Response<Void> join(@RequestBody ZoneUserApplyJoinDTO req) {
        Session<LoginUserDTO> session = sessionManager.get();
        req.setUserId(session.getData().getId());
        zoneUserApplyService.join(req);
        return Response.success();
    }

    @ApiOperation("申请审核")
    @PostMapping("/audit")
    public Response<ZoneUserDTO> audit(@RequestBody ZoneUserApplyAuditDTO req) {
        zoneUserApplyService.audit(req);
        return Response.success();
    }

}
